package cn.venny.doudian.utils;

import java.util.Objects;

/**
 * @author Vick C
 * @version 1.0
 * @date 2020/11/23 13:07
 * @description ConvetorUtils
 */
public class ConvetorUtils {


    /**
     * obj to str
     * @param obj the obj
     * @return the str
     */
    public static String objToString(Object obj) {
        if (Objects.isNull(obj)) {
            return "";
        }
        return String.valueOf(obj);
    }

    /**
     * obj to integer
     */
    public static Integer objToInteger(Object obj) {
        return objToInteger(obj, null);
    }

    /**
     * obj to integer
     */
    public static Integer objToInteger(Object obj, Integer defaultValue) {
        if (Objects.isNull(obj)) {
            return defaultValue;
        }
        return Integer.parseInt(String.valueOf(obj));
    }

    /**
     * obj to long
     */
    public static Long objToLong(Object obj) {
        return objToLong(obj, null);
    }

    /**
     * obj to long
     */
    public static Long objToLong(Object obj, Long defaultValue) {
        if (Objects.isNull(obj)) {
            return defaultValue;
        }
        return Long.parseLong(String.valueOf(obj));
    }

    public static Float objToFloat(Object obj) {
        return objToFloat(obj, null);
    }


    public static Float objToFloat(Object obj, Float defaultValue) {
        if (Objects.isNull(obj)) {
            return defaultValue;
        }
        return Float.parseFloat(String.valueOf(obj));
    }

    /**
     * ks订单状态码转pdd订单发货状态码
     * @param ksOrderStatus ks订单状态码
     * @return pdd订单发货状态码
     */
    public static Integer ksOrderStatusToPddOrderStatus(int ksOrderStatus) {
        // 1：待发货，2：已发货待签收，3：已签收 0：异常
        switch (ksOrderStatus) {
            // 30, "已付款"
            case 30:
                return 1;
            // 40, "已发货"
            case 40:
                return 2;
            // 50, "已签收"
            case 50:
                return 3;
            // 0, "未知状态"
            case 0:
                // 10, "待付款"
            case 10:
                // 70, "订单成功"
            case 70:
                // 80, "订单失败"
            case 80:
            default:
                return 0;
        }
    }

    /**
     * @param ksRefundStatus 退款状态：0-未知状态；10-买家仅退款申请；11-买家退货退款申请；20-平台介入-买家仅退款申请；
     *                       21-平台介入-买家退货退款申请；22-平台介入-已确认退货退款；30-商品回寄信息待买家更新；
     *                       40-商品回寄信息待卖家确认；50-退款执行中；60-退款成功；70-退款失败。
     */
    public static Integer ksRefundStatusToPddRefundStatus(int ksRefundStatus) {
        /*
            _0(0,"异常"),
            _1(1, "无售后或售后关闭"),
            _2(2, "售后处理中"),
            _3(3, "退款中"),
            _4(4, "退款成功")
         */
        switch (ksRefundStatus) {
            case 0:
                return 1;
            case 10:
            case 11:
            case 20:
            case 21:
            case 22:
            case 30:
            case 40:
                return 2;
            case 50:
                return 3;
            case 60:
                return 4;
            default:
                return 0;
        }
    }

    /**
     * @param payType 支付方式 1微信 2支付宝
     * @return pdd pay type
     */
    public static String psPayTypeToPddPayType(int payType) {
        // target枚举值：QQ,WEIXIN,ALIPAY,LIANLIANPAY
        switch (payType) {
            case 1:
                return "WEIXIN";
            case 2:
                return "ALIPAY";
            default:
                return null;
        }
    }

    /**
     * @param payType 支付类型 (0：货到付款，1：微信，2：支付宝,·4：银行卡,5：余额, 8：Dou分期, 9：新卡支付）
     */
    public static String dyPayTypeToPddPayType(Integer payType) {
        // // target枚举值：QQ,WEIXIN,ALIPAY,LIANLIANPAY
        switch (payType) {
            case 1:
                return "WEIXIN";
            case 2:
                return "ALIPAY";
            case 5:
                return "BALANCE";
            case 8:
                return "DOU_STAGING";
            case 4:
            case 9:
            default:
                return null;
        }
    }
}
